package com.ghsc.ghxc.jsb.ui.message.activity

import androidx.lifecycle.MutableLiveData
import com.cn.appcore.base.BaseViewModel
import com.cn.appcore.ext.executeListResponse
import com.cn.appcore.ext.executeResponse
import com.cn.appcore.http.bean.BaseListResponse
import com.cn.appcore.http.bean.BaseResponse
import com.ghsc.ghxc.jsb.api.ApiMarket
import com.ghsc.ghxc.jsb.ui.message.bean.ChatDataResult
import com.ghsc.ghxc.jsb.ui.message.bean.GetUserInfoResult
import com.ghsc.ghxc.jsb.ui.message.bean.GroupDataResult
import com.ghsc.ghxc.jsb.ui.message.bean.GroupDataResultBeans
import com.ghsc.ghxc.jsb.ui.message.bean.GroupUserInfoResult
import com.ghsc.ghxc.jsb.ui.message.bean.UserRyResult
import com.ghsc.ghxc.jsb.ui.my.bean.OssTokenResultDataBean
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext

/**
 * 项目：GuoHuaJsb
 * 包名：com.ghsc.ghxc.jsb.ui.message.activity
 * 类名：ChatViewModel
 * 创建时间：2024/5/8 12:06
 * 创建人 @author： xiaolin
 * 描述 ：Todo...
 */
class ChatViewModel : BaseViewModel() {

    /**  查询用户名片 **/
    var onGetUserInfoData = MutableLiveData<BaseResponse<GetUserInfoResult>>()
    fun onGetUserInfoMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGetUserInfoData(paras) }
            executeResponse(
                response,
                { onGetUserInfoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }

    /** 好友删除 **/
    var onDeleteFriendData = MutableLiveData<BaseResponse<Any>>()
    fun onDeleteFriendMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onDeleteFriendData(paras) }
            executeResponse(
                response,
                { onDeleteFriendData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /** 申请添加 **/
    var onAddFriendData = MutableLiveData<BaseResponse<Any>>()
    fun onAddFriendMethod(paras: String) {
        launch {
            val response =
                withContext(Dispatchers.IO) { ApiMarket.service.onAddFriendData(paras) }
            executeResponse(
                response,
                { onAddFriendData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }


    /**  根据群id 查询个人信息 是否是管理员或者群主 **/
    var onGroupUserInfoData = MutableLiveData<BaseResponse<GroupUserInfoResult>>()
    fun onGroupUserInfoMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupUserInfoData(paras) }
            executeResponse(
                response,
                { onGroupUserInfoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }

    /**  根据群id 查询个人信息 是否是管理员或者群主 **/
    var onGroupUserInfoToData = MutableLiveData<BaseResponse<GroupUserInfoResult>>()
    fun onGroupUserInfoToMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupUserInfoData(paras) }
            executeResponse(
                response,
                { onGroupUserInfoToData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /**  群设置管理员  **/
    var onGroupAdminData = MutableLiveData<BaseResponse<Any>>()
    fun onGroupAdminMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupAdminData(paras) }
            executeResponse(
                response,
                { onGroupAdminData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /**  群 禁言 个人 **/
    var onGroupStopuserData = MutableLiveData<BaseResponse<Any>>()
    fun onGroupStopuserMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupStopuserData(paras) }
            executeResponse(
                response,
                { onGroupStopuserData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /**  群拉人或者删除人  **/
    var onGroupJoinData = MutableLiveData<BaseResponse<Any>>()
    fun onGroupJoinMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupJoinData(paras) }
            executeResponse(
                response,
                { onGroupJoinData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }



    /** 群的好友信息 **/
    var onGroupInfoData = MutableLiveData<BaseResponse<GroupDataResult>>()
    fun onGroupInfoMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupInfoData(paras) }
            executeResponse(
                response,
                { onGroupInfoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }

    /**  解散群 **/
    var onDeleteGroupData = MutableLiveData<BaseResponse<Any>>()
    fun onDeleteGroupMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onDeleteGroupData(paras) }
            executeResponse(
                response,
                { onDeleteGroupData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }


    /** 退出群 **/
    var onExitGroupData = MutableLiveData<BaseResponse<Any>>()
    fun onExitGroupMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onExitGroupData(paras) }
            executeResponse(
                response,
                { onExitGroupData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }


    /**  修改群基本信息 **/
    var onUpGroupInfoData = MutableLiveData<BaseResponse<Any>>()
    fun onUpGroupInfoMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onUpGroupInfoData(paras) }
            executeResponse(
                response,
                { onUpGroupInfoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }

    /**  、好友备注 **/
    var onUpFriendMemoData = MutableLiveData<BaseResponse<Any>>()
    fun onUpFriendMemoMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) {  ApiMarket.service.onUpFriendMemoData(paras) }
            executeResponse(
                response,
                { onUpFriendMemoData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }

    /** 阿里云oos **/
    var onAliYunOosData = MutableLiveData<BaseResponse<OssTokenResultDataBean>>()
    fun onAliYunOosMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onAliYunOosData(paras) }
            executeResponse(
                response,
                { onAliYunOosData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

    /**  群 禁言 all  **/
    var onGroupStopAllData = MutableLiveData<BaseResponse<Any>>()
    fun onGroupStopAllMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupStopAllData(paras) }
            executeResponse(
                response,
                { onGroupStopAllData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }
    /**  群 禁私聊 all  **/
    var onGroupSiXinData = MutableLiveData<BaseResponse<Any>>()
    fun onGroupSiXinMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onGroupSiXinData(paras) }
            executeResponse(
                response,
                { onGroupSiXinData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }


    /** 群的好友信息 全部 **/
    var onGroupInfoListData = MutableLiveData<BaseResponse<GroupDataResult>>()
    fun onGroupInfoListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) {  ApiMarket.service.onGroupInfoListData(paras) }
            executeResponse(
                response,
                { onGroupInfoListData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }
        }
    }




    /** 好友列表 **/
    var onFriendListData = MutableLiveData<BaseResponse<ChatDataResult>>()
    fun onFriendListMethod(paras: String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onFriendListData(paras) }
            executeResponse(
                response,
                { onFriendListData.value = response },
                { againLoginMsg.value = response.msg }
            ) { errorMsg.value = response.msg }
        }
    }




    /** 创建群聊 **/
    var onCrtGroupData = MutableLiveData<BaseResponse<UserRyResult>>()
    fun onCrtGroupMethod(paras:String) {
        launch {
            val response = withContext(Dispatchers.IO) { ApiMarket.service.onCrtGroupData(paras) }
            executeResponse(
                response,
                { onCrtGroupData.value = response},
                { againLoginMsg.value = response.msg}
            ) { errorMsg.value = response.msg }

        }
    }

}